package main

import (
	"fmt"
	"math"
	"sort"
)

func findRadius(houses []int, heaters []int) int {
	var max = 0
	sort.Ints(heaters)
	len := len(heaters)
	for _, house := range houses {
		var i = 0
		for ; i < len && heaters[i] < house; i++ {
		}
		if i == 0 {
			max = int(math.Max(float64(max), float64(heaters[0]-house)))
		} else if i == len {
			max = int(math.Max(float64(max), float64(house-heaters[len-1])))
		} else {
			var right = heaters[i] - house
			right = int(math.Min(float64(right), float64(house-heaters[i-1])))
			max = int(math.Max(float64(max), float64(right)))
		}
	}
	return max
}

func main() {
	fmt.Println(findRadius([]int{1, 5}, []int{2}))
	fmt.Println(findRadius([]int{1, 2, 3, 5, 15}, []int{2, 30}))
	fmt.Println(findRadius([]int{1, 1, 1, 1, 1, 1, 999, 999, 999, 999, 999}, []int{499, 500, 501}))
}
